package com.ewzj.bigdata.mvp.model

import com.ewzj.bigdata.app.config.netmodel.CommonCache
import com.ewzj.bigdata.app.config.netmodel.CommonService
import com.ewzj.bigdata.app.extensions.json2Body
import com.ewzj.bigdata.mvp.contract.CitySelectorActivityContract
import com.ewzj.bigdata.mvp.contract.DecorateContract
import com.ewzj.bigdata.mvp.contract.EditProfileActivityContract
import com.ewzj.bigdata.mvp.model.reqbean.ReqCityBean
import com.ewzj.bigdata.mvp.model.reqbean.ReqSearchCityBean
import com.ewzj.bigdata.mvp.model.reqbean.ReqSelfInfoData
import com.ewzj.bigdata.mvp.model.reqbean.Reqpagebean
import com.ewzj.bigdata.mvp.model.rspbean.BaseData
import com.ewzj.bigdata.mvp.model.rspbean.CityBean
import com.ewzj.bigdata.mvp.model.rspbean.CitySearchBean
import com.google.gson.Gson
import com.jess.arms.integration.IRepositoryManager
import com.jess.arms.mvp.BaseModel
import io.reactivex.Observable
import io.rx_cache2.DynamicKey
import io.rx_cache2.EvictDynamicKey
import okhttp3.MediaType
import okhttp3.MultipartBody
import okhttp3.RequestBody
import java.io.File
import javax.inject.Inject

/**
 * author:zhangjing
 * 作用:
 * return:
 */
class EditProfileActivityModel @Inject constructor(val mGson:Gson, repositoryManager: IRepositoryManager) :BaseModel(repositoryManager),EditProfileActivityContract.Model{
    val service=repositoryManager.obtainRetrofitService(CommonService::class.java)
    val cache=repositoryManager.obtainCacheService(CommonCache::class.java)

    override fun upLoadPic(file: File) : Observable<BaseData<List<String>>>{

        val builder = MultipartBody.Builder().setType(MultipartBody.FORM)
                .addFormDataPart("mode", "AVATAR")
        //表单类型;
        val imageBody = RequestBody.create(MediaType.parse("multipart/form-data"), file)
        builder.addFormDataPart("filed1", file.getName(), imageBody)//imgfile 后台接收图片流的参数名
        val parts = builder.build().parts()
        return service.uploadPic(parts)
    }

    override fun updateUserinfo(reqSelfInfoData: ReqSelfInfoData): Observable<BaseData<Any>> {
        return service.updateUser(json2Body(mGson.toJson(reqSelfInfoData)))
    }
}